import requests
import pymysql
import pandas as pd
import json
import threadpool
import re
import time
import parsel
import datetime
import zhconv

class Load:
    def __init__(self):
        self.conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                                    database='sunway_db', charset='utf8')
        self.cursor = self.conn.cursor()

        self.list1 = []


    def mysql_one(self,Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,deliveredDate, remark,
                  mysql_name):  # 四个参数的mysql
        conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                                    database='sunway_db', charset='utf8')
        cursor = conn.cursor()
        newtime = time.strftime('%Y-%m-%d %H:%M:%S')
        # conn.ping(reconnect=True)
        cursor.execute(
            "REPLACE into {} set newtime=%s,Primary_key=%s,times=%s,title=%s,describes=%s,Tracking_number=%s,warehouse_sku=%s,zhujian=%s,deliveredDate=%s,remark=%s".format(
                mysql_name),
            [newtime,Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,deliveredDate, remark])

        conn.commit()

    def mysql_two(self,Primary_key, times, title, describes, Tracking_number, warehouse_sku, pIds, zhujian, remark,
                  mysql_name):  # 五个参数的MySQL
        conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                                    database='sunway_db', charset='utf8')
        cursor = conn.cursor()
        newtime = time.strftime('%Y-%m-%d %H:%M:%S')
        # conn.ping(reconnect=True)
        cursor.execute(
            "REPLACE into {} set newtime=%s,Primary_key=%s,times=%s,title=%s,describes=%s,Tracking_number=%s,warehouse_sku=%s,pIds=%s,zhujian=%s,remark=%s".format(
                mysql_name),
            [newtime,Primary_key, times, title, describes, Tracking_number, warehouse_sku, pIds, zhujian, remark])

        conn.commit()

    def mysql_three(self,Primary_key, times, title, Tracking_number, warehouse_sku, zhujian, remark, mysql_name):  # 三个参数的MySQL
        newtime = time.strftime('%Y-%m-%d %H:%M:%S')
        conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                                    database='sunway_db', charset='utf8')
        cursor = conn.cursor()
        # conn.ping(reconnect=True)
        cursor.execute(
            "REPLACE into {} set newtime=%s,Primary_key=%s,times=%s,title=%s,Tracking_number=%s,warehouse_sku=%s,zhujian=%s,remark=%s".format(
                mysql_name),
            [newtime,Primary_key, times, title, Tracking_number, warehouse_sku, zhujian, remark])

        conn.commit()



    def return_mysql(self):  # 获取数据库中的跟踪号和运输方式
        datas = "select track_code,logistics_method,warehouse_sku,zhujian,fba_status from det_fba_first_shipment_product"
        a = pd.read_sql(datas, self.conn)
        # print( a['warehouse_sku'])
        # for i in a['Title']:
        #     print(i)
        track_code_all = a['track_code']
        logistics_method_all = a['logistics_method']
        warehouse_sku_all = a['warehouse_sku']
        zhujian_all = a['zhujian']
        fba_status = a['fba_status']
        # print(len(track_code_all))
        list_all = []
        list_all_ = []
        for jj in range(len(track_code_all)):
            if str(track_code_all[jj]) != 'None' and track_code_all[jj] not in list_all_:

                list_all_.append(track_code_all[jj])
                all = str(track_code_all[jj]) + '我是你哥' + str(logistics_method_all[jj]) + '我是你哥' + str(
                    warehouse_sku_all[jj] + '我是你哥' + str(zhujian_all[jj]) + '我是你哥' + str(fba_status[jj]))
                list_all.append(all)
        return list_all

    def screening_load(self):  # 甄别物流方式  主函数
        list_ = self.return_mysql()
        task_pool = threadpool.ThreadPool(30)
        requests = threadpool.makeRequests(self.threading_thread, list_)
        # print(requests)
        for req in requests:
            task_pool.putRequest(req)
        task_pool.wait()

    def threading_thread(self, word):
        # print('000000000000000',word)
        words = word.split('我是你哥')
        load = words[1]#运输方式
        load_show = words[0]#跟踪号
        load_sku = words[2]#仓库sku
        zhujian = words[3]#主键
        fba_status = words[4]#状态
        # print(zhujian, load, load_show, load_sku, fba_status)
        # load, load_show, load_sku=list13[0],list13[1],list13[2]
        if fba_status not in ['-1']:
            print(zhujian, load, load_show, load_sku, fba_status)
            if 'ups'.lower() in load.lower():
                # print(1)
                try:
                    self.ups(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark = '', '', '', load_show, load_sku, zhujian,'', '无数据'
                    Primary_key = zhujian + str(times) + title
                    print('ups', times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark)
                    self.mysql_one(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark,
                                   mysql_name='load_ups')

            elif 'fedex'.lower() in load.lower():
                # print(11)
                try:
                    self.fedex(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark = '', '', '', load_show, load_sku, zhujian,'', '无数据'
                    Primary_key = zhujian + str(times) + title
                    print('fedex', times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark)
                    self.mysql_one(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark,
                                   mysql_name='load_fedex')



            elif 'dhl'.lower() in load.lower():
                # print(111)
                try:
                    self.dhl(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, pIds, zhujians, remark = '', '', '', load_show, load_sku, '', zhujian, '无数据'
                    Primary_key = zhujian + str(times) + title
                    print('dhl', times, title, describes, Tracking_number, pIds, zhujians, remark)
                    self.mysql_two(Primary_key,times, title, describes, Tracking_number, warehouse_sku, pIds, zhujians, remark,
                                   mysql_name='load_dhl')
            elif '九方' in load.lower():
                # print(1111)
                try:
                    self.jiufang(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, Tracking_number, warehouse_sku, zhujians, remark = '', '', load_show, load_sku, zhujian, '无数据'
                    Primary_key = zhujian + str(times) + title
                    print('九方', times, title, Tracking_number, warehouse_sku, zhujians, remark)
                    self.mysql_three(Primary_key,times, title, Tracking_number, warehouse_sku, zhujians, remark,
                                     mysql_name='load_jiufang')

            elif 'aaf'.lower() in load.lower():
                try:
                    self.aff_1(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, zhujians, deliveredDate, remark = '', '', '', load_show, load_sku, zhujian, '', '无数据'
                    Primary_key = zhujian + str(times) + title
                    print('aff', times, title, describes, Tracking_number, warehouse_sku, zhujians, deliveredDate,remark)
                    self.mysql_one(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians, deliveredDate,remark, mysql_name='load_aff')


            else:
                print(11111)

            # try:
            #     print(1)
            #     self.ups(self.return_mysql()[0][i])
            # except Exception as g:
            #     try:
            #         print(11)
            #         self.fedex(self.return_mysql()[0][i])
            #     except Exception as g:
            #         try:
            #             print(111)
            #             self.dhl(self.return_mysql()[0][i])
            #         except Exception as g:
            #             try:
            #                 print(1111)
            #                 self.jiufang(self.return_mysql()[0][i])
            #             except Exception as g:
            #                 print(11111)

        else:
            print('iiii')

    def aff(self):
        cookie_Token_ = self.login_1()
        url = 'http://aafgzx.nextsls.com/wos/shipment/index?kw=GZBL2202029916&waybill_number=&service=&daterange=&created_daterange=&country=&name=&store_id='
        headers = {
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Connection': 'keep-alive',
            'Cookie': '{}'.format(cookie_Token_[1]),
            'Host': 'aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/shipment/index?status=picked',
            'Upgrade-Insecure-Requests': '1',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',

        }

        response = requests.get(url, headers=headers).text
        # print(response)
        response_parsel = parsel.Selector(response)
        response_parsel_country = response_parsel.css(
            '#w0 > table > tbody > tr > td:nth-child(5)::text').extract_first()
        # print(response_parsel_country)
        response_tbody = re.findall('<tbody>(.*?)</tbody>', response, re.S)[0]
        response_data_key = re.findall('data-key="(.*?)"', response_tbody)[0]
        # print(response_data_key)
        return [cookie_Token_[0], cookie_Token_[1], response_data_key, response_parsel_country]

    def aff_1(self,load_show, load_sku, zhujian):
        # print('opooo')
        times1 = int(time.time() * 1000)
        id_cookie_token = self.aff()
        url = 'http://aafgzx.nextsls.com/wos/shipment/show_traces?id={}&lmodal=1&_={}'.format(
            id_cookie_token[2], times1)
        # print(url)
        headers = {
            'Accept': '*/*',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Connection': 'keep-alive',
            'Cookie': '{}'.format(id_cookie_token[1]),
            'Host': 'aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/shipment/index?status=delivered',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
            'X-CSRF-Token': '{}'.format(id_cookie_token[0]),
            'X-Requested-With': 'XMLHttpRequest',
        }
        # print(headers)
        param = {
            'id': '{}'.format(id_cookie_token[2]),
            'lmodal': '1',
            '_': '{}'.format(times1)

        }
        response = requests.get(url, headers=headers, params=param).text
        # print(response)
        response_parsel = parsel.Selector(response)
        response_parsel_ = response_parsel.css('#one-column > div')
        # print(response_parsel_)
        for response_parsel_div in response_parsel_:
            # print(id_cookie_token[3])#国家
            response_parsel_div_ = response_parsel_div.css('div > div.message-head.clearfix::text').get().strip()#时间
            # print(response_parsel_div_)
            response_parsel_div_span = response_parsel_div.css('div > div.qa-message-content span::text').get().strip()#标题
            print(id_cookie_token[3],response_parsel_div_,response_parsel_div_span)
            times, title, describes, Tracking_number, warehouse_sku, zhujians, deliveredDate, remark = response_parsel_div_,response_parsel_div_span,id_cookie_token[3],load_show, load_sku, zhujian,'',''
            Primary_key = zhujians+str(times)+title
            self.mysql_one(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians, deliveredDate, remark,
                           mysql_name='load_aff')

    def login_(self):
        url = 'http://aafgzx.nextsls.com/wos/login/'
        headers = {

            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'grid-view-pagesize=10',
            'Host': 'aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/login/',
            'Upgrade-Insecure-Requests': '1',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',

        }
        response = requests.get(url, headers=headers)
        # print(response.headers['Set-Cookie'])
        # print(re.findall('<meta name="csrf-token" content="(.*)">', response.text))
        return [response.headers['Set-Cookie'], re.findall('<meta name="csrf-token" content="(.*)">', response.text)[0]]

    def login_1(self):
        cookie_Token = self.login_()
        url = 'http://aafgzx.nextsls.com/wos/login'
        headers = {

            'Accept': 'application/json, text/javascript, */*; q=0.01',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Connection': 'keep-alive',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Cookie': '{}'.format(cookie_Token[0]),
            'Host': 'aafgzx.nextsls.com',
            'Origin': 'http://aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/login/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
            'X-CSRF-Token': '{}'.format(cookie_Token[1]),
            'X-Requested-With': 'XMLHttpRequest',

        }

        data = {
            'username': '广州盛业',
            'password': '123456',
            'inajax': '1'
        }
        response = requests.post(url, headers=headers, data=data).headers
        cookie = '_csrf-parcelos-wos' + re.findall('_csrf-parcelos-wos(.*?);', cookie_Token[0])[
            0] + ';' + 'parcelos_wos=' + \
                 re.findall('parcelos_wos=(.*?);', response['Set-Cookie'])[0]
        # print(cookie)
        return [cookie_Token[1], cookie]


    def jiufang(self,jiufang_load, warehouse_sku, zhujians):
        url = 'http://www.tofba.com:8081/seaair/waybills/listPage'
        headers = {
            'Accept': 'application/json, text/plain, */*',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJyZWdpc3RlcmVkTW9iaWxlUGhvbmVOdW1iZXIiOiIxODAyODU2OTY0MCIsInN1YiI6IjM4NzgiLCJjdXN0b21lckxvZ2luTmFtZSI6IlNXRFpTVyIsImlzcyI6ImF1dGhvciIsImN1c3RvbWVyQ29kZSI6Iko0MjQ1IiwiaWQiOjM4NzgsImV4cCI6MTYyMTg0MzY0NiwiaWF0IjoxNjIxODQzNjQ2LCJqdGkiOiIyY2VjOTYwMC0yODI4LTRiMmQtODRmZS0yYTE1MTk2YjQwOTEiLCJjdXN0b21lck5hbWVTaG9ydCI6Iuebm-S4uueUteWtkOWVhuWKoSJ9.D4BRKMUuV5bf6JS6dkydn1-9Z0CjbOUbqppqhMviA8E',
            'Cache-Control': 'no-cache',
            'Content-Length': '209',
            'Content-Type': 'application/json; charset=UTF-8',
            'Host': 'www.tofba.com:8081',
            'Origin': 'http://tofba.com:8887',
            'Pragma': 'no-cache',
            'Proxy-Connection': 'keep-alive',
            'Referer': 'http://tofba.com:8887/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'x-tofba-session-status': 'y',
        }
        parm = json.dumps(
            {"status": [0], "inStockChannel": "", "waybillNo": "{}".format(jiufang_load), "trackNumber": "",
             "referenceNo": "",
             "countryId": "", "declareNameCn": "", "sku": "", "dispatchAddressCode": "", "shipmentID": "",
             "pageSize": 20, "currentPage": 1})
        parm1 = json.dumps(
            {"status": [0], "inStockChannel": "", "waybillNo": "", "trackNumber": "",
             "referenceNo": "",
             "countryId": "", "declareNameCn": "", "sku": "", "dispatchAddressCode": "",
             "shipmentID": "{}".format(jiufang_load),
             "pageSize": 20, "currentPage": 1})
        if jiufang_load[:2] == 'ZX':
            res = requests.post(url, headers=headers, data=parm,timeout=10).json()
        else:
            res = requests.post(url, headers=headers, data=parm1,timeout=10).json()
        # print(res)
        # print(res['datas'][0]['id'])
        id = res['datas'][0]['id']
        self.jiufang_run(jiufang_load, id, warehouse_sku, zhujians)


    def jiufang_run(self, jiufang_load, id, warehouse_sku, zhujians):
        url = 'http://www.tofba.com:8081/seaair/waybills/initWaybillState?id={}'.format(id)
        headers = {
            'Host': 'www.tofba.com:8081',
            'Connection': 'keep-alive',
            'Content-Length': '0',
            'Pragma': 'no-cache',
            'Cache-Control': 'no-cache',
            'Accept': 'application/json, text/plain, */*',
            'x-tofba-session-status': 'y',
            'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJyZWdpc3RlcmVkTW9iaWxlUGhvbmVOdW1iZXIiOiIxODAyODU2OTY0MCIsInN1YiI6IjM4NzgiLCJjdXN0b21lckxvZ2luTmFtZSI6IlNXRFpTVyIsImlzcyI6ImF1dGhvciIsImN1c3RvbWVyQ29kZSI6Iko0MjQ1IiwiaWQiOjM4NzgsImV4cCI6MTYyMTg0MzY0NiwiaWF0IjoxNjIxODQzNjQ2LCJqdGkiOiIyY2VjOTYwMC0yODI4LTRiMmQtODRmZS0yYTE1MTk2YjQwOTEiLCJjdXN0b21lck5hbWVTaG9ydCI6Iuebm-S4uueUteWtkOWVhuWKoSJ9.D4BRKMUuV5bf6JS6dkydn1-9Z0CjbOUbqppqhMviA8E',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Origin': 'http://tofba.com:8887',
            'Referer': 'http://tofba.com:8887/',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        }
        res = requests.post(url, headers=headers,timeout=10).json()
        # print(res['data'])
        for j in res['data']:
            # print(j)
            times = j['operationDateTime']
            title = j['content']
            Tracking_number = jiufang_load
            remark = 'True'
            if title == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            self.mysql_three(Primary_key,times, title, Tracking_number, warehouse_sku, zhujians, remark, mysql_name='load_jiufang')

    def dhl(self,dhl_load, warehouse_sku, zhujians):
        url = 'https://mydhl.express.dhl/shipmentTracking?AWB={}&countryCode=hk&languageCode=zh'.format(
            str(dhl_load)[:-2])
        headers = {
            'Accept': 'application/json, text/plain, */*',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Connection': 'keep-alive',
            # 'Cookie': 'ewfSessionId=1478297327159025664; BIGipServer~EWF~pl_internal-ewf-cbj.dhl.com_1443=4288817351.41733.0000; OptanonAlertBoxClosed=2022-01-04T09:29:32.457Z; s_ccst={%22target%22:true%2C%22ecid%22:true%2C%22aa%22:true}; AMCVS_9D88879D5579828F7F000101%40AdobeOrg=1; s_cc=true; AKA_A2=A; bm_sz=44D07E5C8B47164FCC3CF691650E0FF0~YAAQlPffF25heaJ9AQAAvQGJKQ4HHf6UCH5ppImtwFMD47Z/YPznrf8+9G8TVCMrF8eHLpMgwAg0D3tx4NBK9sIConIieDbL/CYNyBoWosBIXAXGNeIC5ME5lT1OX4YB56yu916FgwfglXHr3lw4G6MA2E9DUVyRaMlhHCkUY6Sp+hRoACXW9pfdJbQDxuPz4S25gex8XQr6Oa989F/pMG0aOzIkYuIdR8xUOFRxI5iUN8XB60QED5sBm7bJv7DJ3jZdXOsfnMQo+aYZktRhzT7sTS6NP8B/qh4Gphf+I+PRg/D0~4405559~4407863; TS0136675b=01914b743d6c92b6d0e74b471ede10eb13bef80773e8520b5ab20b620f4baa32a9371d75f072e4319f642c52cdd5183b48aa319672; RT="z=1&dm=express.dhl&si=jnqhcsbbrh&ss=kxzwt433&sl=0&tt=0"; ak_bmsc=FC45B8E207F03F6D387FE062DB260EEB~000000000000000000000000000000~YAAQlPffF9pheaJ9AQAArQuJKQ6Hw7wtUPaEqV7WG9caOFcf/iT++Qgvp4Ty06nicgCWzmCu/iTKc0XzfORs7QsT312epz0BbjL6o3HOhmfegKnTikCdyy4eTjr0zlokrUXTELwJk3EOIIEkMNSr40y+HbhQBTtAkm47Tz1WvVVI1wiNCk0vboHqqvXPiiKSSY+p5uX1sf3sls2LY1Fp3EzMDwKcbift6UcUIJ+o77rvWS1uoZ4nc+FGCQSJHb7IqziQbrOUrqMWsCGg1QIjtS2q5oPVIJt5wR3Tvf9ecFLdnwyRHGZvFJciht1Omz944Uya6U0C/U/71rgM8XpCpCat6NPNF4nqtMZljCcbfQvgL9PxDeO7dho30qKcz1DqQuhCTEFYKkdKaZp9xmMDnPLdMfLVQiEg9D0R3187tmHVYFrJ6L2V32goCbCmxqEf+8XU5z9Q3z8Zw5GTTJfIHpqSVD07yaWPDXCjr/GKMw==; OptanonConsent=isGpcEnabled=0&datestamp=Wed+Jan+05+2022+17%3A19%3A14+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.26.0&isIABGlobal=false&consentId=419437aa-265f-4cf7-86ef-96cb4b583f3a&interactionCount=1&landingPath=NotLandingPage&groups=C0001%3A1%2CC0002%3A1%2CC0003%3A1%2CC0004%3A1%2CYOU01%3A1&hosts=H290%3A1%2CH224%3A1%2CH223%3A1%2CH222%3A1%2CH292%3A1%2CH293%3A1%2CH291%3A1%2CH214%3A1%2CH221%3A1%2CH44%3A1%2CH295%3A1%2CH2%3A1%2CH21%3A1%2CH175%3A1%2CH29%3A1%2CH38%3A1&geolocation=%3B&AwaitingReconsent=false; _abck=E40B652D5C743577A1DEC1A8EE280F02~0~YAAQlPffFxZieaJ9AQAABBGJKQc2c9guw85YQbwhdIcRt1QgPlHTNomx2GJoHqnsI6C483bIHRYDgVvUs8oYbrHvioCyFwp8LaUfhq2/HltTe+IMF6TvSIxilEBUkN787nLeedwVsYI6JYHlwL4119D1urVZ+qMQD3WARxnlqJhYwd9f8Mo17ZQWhU02w0ycQLA5dwEIZR9VwMvUD9Y9wwWsS7zswDgB20ofTeaOjILNQJB52/SX2Tsq29/A7iaJdbudzKlq/BnzyL6ccpjae99nGMh1ActRtf2aHZmlq/lZ3e+pqyoBmtPXeJ4tiGp9QC0WNe3VxqFiSdzEPw21QSkJyejVW6kEBfMeKgfhMA45CPDapxzoqxbcdKy+oneHhCTYu1oIKTVDGf0j/dRjULD1m7dSwScD3w==~-1~||-1||~-1; AMCV_9D88879D5579828F7F000101%40AdobeOrg=1585540135%7CMCIDTS%7C18997%7CMCMID%7C54790893569662697931796380628130773111%7CMCAAMLH-1641979156%7C11%7CMCAAMB-1641979156%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641381556s%7CNONE%7CvVersion%7C4.4.0; s_sq=%5B%5BB%5D%5D; bm_sv=B1635F20C5975979764D3569AE1ED450~diJG2rCuwUi+mBw89Kw9A4Xx1TYt24dBDQJgCfszRCk0kZiIo2o+ncqr4KqS+O3lyLKtxvkqXLzHBSzLJRgMVoohBD/UC+2tfdWJPVNLUYg7y5YoC8GveQGnOI31kKKKwqjllkKHq1/SIbwdIlNhW3OgOjbiyomMFcr2CaQ8sRE=',
            'Host': 'mydhl.express.dhl',
            'Referer': 'https://mydhl.express.dhl/hk/zh/tracking.html',
            'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            'sec-ch-ua-mobile': '?0',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-origin',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
        }
        parm = {
            'AWB': '{}'.format(str(dhl_load)[:-2]),
            'countryCode': 'hk',
            'languageCode': 'zh',
        }
        res = requests.get(url, headers=headers, params=parm, verify=False,timeout=10).json()
        # print(res)
        for i in res['results'][0]['checkpoints']:
            # print(i)
            times = i['date'] + ' ' + i['time']
            title = i['description']
            describes = i['location']
            Tracking_number = dhl_load
            remark = 'True'
            if title == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            try:
                pIds = ''
                for o in i['pIds']:
                    pIds = pIds + ',' + o

                self.mysql_two(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians, remark, pIds,
                               mysql_name='load_dhl')
            except KeyError as g:
                pIds = ''
                self.mysql_two(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians, remark, pIds,
                               mysql_name='load_dhl')

    def fedex(self,fedex_load, warehouse_sku, zhujians):
        url = 'https://www.fedex.com/trackingCal/track'
        headers = {
            'Host': 'www.fedex.com',
            # 'Connection': 'keep-alive',
            'Content-Length': '459',
            # 'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            # 'Accept': '*/*',
            'ADRUM': 'isAjax:true',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Origin': 'https://www.fedex.com',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://www.fedex.com/zh-cn/home.html',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
        }
        parm1 = {
            'action': 'trackpackages',
            'data': json.dumps({"TrackPackagesRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                         "processingParameters": {}, "uniqueKey": "",
                                                         "supportCurrentLocation": True, "supportHTML": True,
                                                         "trackingInfoList": [{"trackNumberInfo": {
                                                             "trackingNumber": "{}".format(fedex_load),
                                                             "trackingQualifier": "",
                                                             "trackingCarrier": ""}}]}}),
            'format': 'json',
            'locale': 'zh_CN',
            'version': '1',

        }

        res1 = requests.post(url, headers=headers, data=parm1, verify=False,timeout=10).json()
        number = res1['TrackPackagesResponse']['packageList'][0]['masterQualifier']  # 2459543000
        # print(number)  # masterQualifier  ['scanEventList']
        remark = 'True'
        for i in res1['TrackPackagesResponse']['packageList'][0]['scanEventList']:
            # print(i)
            # print('主{}'.format(i))
            print('*' * 30)
            times = i['date'] + ' ' + i['time']
            title = i['status']
            describes = i['scanLocation']
            Tracking_number = fedex_load
            zhujian = zhujians
            deliveredDate = ''

            if title == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            self.mysql_one(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujian,deliveredDate, remark,
                           mysql_name='load_fedex')
        print('#' * 30)
        self.fedex_run1(fedex_load, number, warehouse_sku, zhujians, remark)

    def fedex_run1(self,fedex_load, number, warehouse_sku, zhujians, remark):
        url = 'https://www.fedex.com/trackingCal/track'
        headers = {
            'Host': 'www.fedex.com',
            # 'Connection': 'keep-alive',
            # 'Content-Length': '459',
            # 'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            # 'Accept': '*/*',
            'ADRUM': 'isAjax:true',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Origin': 'https://www.fedex.com',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://www.fedex.com/zh-cn/home.html',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
        }
        parm1 = {
            'action': 'getAssociatedShipments',
            'data': json.dumps({"AssociatedShipmentRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                              "processingParameters": {}, "uniqueKey": "",
                                                              "masterTrackingNumberInfo": {"associatedType": "MPS",
                                                                                           "trackingNumberInfo": {
                                                                                               "trackingCarrier": "",
                                                                                               "trackingNumber": "{}".format(
                                                                                                   fedex_load),
                                                                                               "trackingQualifier": "{}".format(
                                                                                                   number)}}}}),
            'format': 'json',
            'locale': 'zh_CN',
            'version': '1',

        }

        res1 = requests.post(url, headers=headers, data=parm1, verify=False,timeout=10).json()
        # print(res1)
        for i in res1['AssociatedShipmentsResponse']['associatedShipmentList'][1:]:
            # print(i['trackingNbr'])
            track = i['trackingNbr']
            self.fedex_run2(track, warehouse_sku, zhujians, remark)

    def fedex_run2(self,track, warehouse_sku, zhujians, remark):
        # print('跟踪号2', track)
        url = 'https://www.fedex.com/trackingCal/track'
        headers = {
            'Host': 'www.fedex.com',
            # 'Connection': 'keep-alive',
            'Content-Length': '459',
            # 'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            # 'Accept': '*/*',
            'ADRUM': 'isAjax:true',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Origin': 'https://www.fedex.com',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://www.fedex.com/zh-cn/home.html',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
        }
        parm1 = {
            'action': 'trackpackages',
            'data': json.dumps({"TrackPackagesRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                         "processingParameters": {}, "uniqueKey": "",
                                                         "supportCurrentLocation": True, "supportHTML": True,
                                                         "trackingInfoList": [{"trackNumberInfo": {
                                                             "trackingNumber": "{}".format(track),
                                                             "trackingQualifier": "",
                                                             "trackingCarrier": ""}}]}}),
            'format': 'json',
            'locale': 'zh_CN',
            'version': '1',

        }

        res1 = requests.post(url, headers=headers, data=parm1, verify=False,timeout=10).json()
        for i in res1['TrackPackagesResponse']['packageList'][0]['scanEventList']:
            # print(i)
            times = i['date'] + ' ' + i['time']
            title = i['status']
            describes = i['scanLocation']
            Tracking_number = track
            deliveredDate = ''
            Primary_key = zhujians + str(times) + title
            self.mysql_one(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark,
                           mysql_name='load_fedex')

    def ups(self,ups_load, warehouse_sku, zhujians):

        url = 'https://www.ups.com/track/api/Track/GetStatus?loc=zh_HK'
        headers = {
            'authority': 'www.ups.com',
            'method': 'POST',
            'path': '/track/api/Track/GetStatus?loc=zh_HK',
            'scheme': 'https',
            'accept': 'application/json, text/plain, */*',
            'accept-encoding': 'gzip, deflate, br',
            'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'content-length': '58',
            'content-type': 'application/json',
            'cookie': 'X-CSRF-TOKEN=CfDJ8Jcj9GhlwkdBikuRYzfhrpLd6d7_2EpfgajHg1rUZNqZdd1LdgI0QjS-1odUQjuSlKGzWLlrN6T2EM7U5Q1-h_Hikc0PYCAlvnbPDJSF7IdAghL-oQJfP6uJYxH_TpxfVFUPckUhHheTXWKeuFEkFV4; at_check=true; CONSENTMGR=consent:true%7Cts:1641288206280; AMCVS_036784BD57A8BB277F000101%40AdobeOrg=1; s_cc=true; _gcl_au=1.1.983945321.1641288208; st_cur_page=st_track; aam_cms=segments%3D22945447%7C9626568%7C9626828; aam_uuid=54786243396233666111792538046679672005; HASSEENNOTICE=TRUE; s_vnum=1643644800768%26vn%3D2; s_invisit=true; dayssincevisit_s=Less%20than%201%20day; bm_sz=753A648612141A6A32FDF89640261607~YAAQZ8U8t9lc3BR+AQAAhx+4Jw6RiqpZoCzGyfkSg2EitU0teK+KUSCzDfA59jOAnWJkX9jQ31DCLszX6NJotMMABbfFWkFxEz10GsCsSYpDq7/q131UEksppRkWZYz/qkUOYDdR6ZFmsfIvWWSoYRZm17a0Ll44VRUG8p6KKqDHGhiAR4ypB9v0kDgI5PDLrA1IppNDLhX0eDCYU7TmHD98zhtB+wKn7kT7L9wY1UYzjfMVzWPgckLLitVh+2448DgrQCjScoTE8aYhZBWbdk+p+H+ChdarlMLQ//JwkYY=~4469047~3618630; mboxEdgeCluster=32; ak_bmsc=E98A1AB992AC73C6412AB4A96545BFCF~000000000000000000000000000000~YAAQZ8U8tyld3BR+AQAAwCS4Jw7YSTPlifYKTL5fTRH2etGqmU0f4OA0Cf7l7mg3JjapC/loNkAH650Jd77OFJAZlGltQA8IXBFoKkYTbORaI+kZya3kc8ZOlqRtAVpBFkAk7yMFpbuzi1HQHcf3GMpkIx2a40bW39037fSjbhZvRftRneGkA9idrnFZVh3tc5ZnmePGNyytMyOG325cKS2v+fz8ZgKmYYpbkh1UWKGscrR4xkaMb0FT531hhNDRHUJvsdxzVh97nspqRWxevuHapTbXhkxi592qgTIQJSDhohO7sUpvWBiShCc8+EsaKDKy+mQabfwZBRavEFSnDxJjuqF9K3y159hCWvR/T97YKnrLNcMgfDhOxvPFQPPSBrThXJBT93sHHR+eGirDmTnOhPXCGgOcQyezwGDSqBSXgZV+ETdr/YgDHi85/kc7d2y4X1Uyi8Su7si3kyBXwQZwZkjnF7auNurNS5auVanIgxC5hsgN2YQ=; AMCV_036784BD57A8BB277F000101%40AdobeOrg=-1124106680%7CMCIDTS%7C18997%7CMCMID%7C55216696863761628391749451949285559553%7CMCAAMLH-1641948687%7C11%7CMCAAMB-1641948687%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641351087s%7CNONE%7CMCCIDH%7C2111192083%7CvVersion%7C5.2.0; ups_language_preference=en_US; sharedsession=a0539fcd-a098-4775-a210-dd36b640161d:w; X-XSRF-TOKEN-ST=CfDJ8Jcj9GhlwkdBikuRYzfhrpIR_U6uCs7mVZuUDQyQxmOKoGcWSzavemYf-TclpDT7cIt8TWYU3W79qj0SFLpxl52i-U5ZE7jewsTxSpOh095ELOdrM8ruQ5wjMVn_g_QSlcmAuiKKCLkIa-yV1l70Hwk; PIM-SESSION-ID=VY7G9k0oEX4hJ8T9; mbox=PC#b6a27b43fde54e70ae0b0b64f1d18095.32_0#1704588727|session#c5fa41c8d9ab40b28adc4e79b621ac3c#1641345746; _abck=63AB01564BFC3D6A0514E0B7098E288B~0~YAAQZsU8t8JQz799AQAAd5K7JwcUnnR07mqTpH9tM/9JuE0/fpF56k0+1cWWFPJFwHIbaT31keXw+0x3f7lKkSHdDYjlRzftr0Bm9jOKiVCuVo12CWYNP/a0J7OmJ28dbELqGYfJ4CWzYEOtGSQonM+EiH2hwgU1b1bXREnjxO4b7Ep4Y9A6ge1KooDpkhhYlMhEpS5ImJ+M67ReSkanCLKPqGsZuOm/OFRi1Je9dD+ikfYnZNodSWkf63zsJVdNkS1uwOYZ1i8EiqJSckdSV04hsLbsDyQSj3SgWbb9QeOJZoxdrfivzDt4kiVmziRvHo02ZFjOsHZ5Tjx4HtGavmZiz0QH3a6kUQzFEGpwDTqdx33IE0ZR4RDUw6sOD+3q6TK/MPNbdDBk7WQrO7FSsy6aX7fx~-1~-1~-1; utag_main=v_id:017e246687bc00126c9d1562327703073005906b00bd0$_sn:2$_se:6$_ss:0$_st:1641345911158$vapi_domain:ups.com$ses_id:1641343886098%3Bexp-session$_pn:2%3Bexp-session$_prevpage:ups%3Ahk%3Azh%3Atrack%3Bexp-1641347711220$_prevpageid:tracking%2FtrackWeb%2Ftra(3det).html%3Bexp-1641347711221; JSESSIONID=F39F2B4D825593C43CA7D1B67652C886; RT="z=1&dm=ups.com&si=b5824023-1117-491a-b068-3e58ad647000&ss=ky0trqja&sl=5&tt=1al4&bcn=%2F%2F684d0d48.akstat.io%2F&ld=9jof"; s_nr=1641344335440-Repeat; dayssincevisit=1641344335441',
            'origin': 'https://www.ups.com',
            'referer': 'https://www.ups.com/track?loc=zh_HK&tracknum={}&requester=WT/'.format(ups_load),
            'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            'sec-ch-ua-mobile': '?0',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'x-xsrf-token': 'CfDJ8Jcj9GhlwkdBikuRYzfhrpIR_U6uCs7mVZuUDQyQxmOKoGcWSzavemYf-TclpDT7cIt8TWYU3W79qj0SFLpxl52i-U5ZE7jewsTxSpOh095ELOdrM8ruQ5wjMVn_g_QSlcmAuiKKCLkIa-yV1l70Hwk'
        }

        parm = {
            "Locale": "zh_HK",
            "TrackingNumber": ["{}".format(ups_load)]
        }

        res = requests.post(url, headers=headers, json=parm,timeout=10).json()
        # print(res)
        for i in res["trackDetails"][0]["shipmentProgressActivities"]:
            # print(i)
            times = i['date'] + i['time']
            if i['activityScan'] == '寄件人建立了標籤，但 UPS 尚未收到包裹。 ':
                title = '已建立標籤'
            elif i['activityScan'] == '您的包裹已經清關，正在派送途中。':
                title = '進口清關'
            elif i['activityScan'] == '在 UPS 設施處理中':
                title = '在途中'
            elif i['activityScan'] == '外出派送':
                title = '派送途中'
            elif i['activityScan'] == '已派送 ':
                title = '已派送'
            else:
                title = ''

            describes = i['activityScan']
            Tracking_number = ups_load
            remark = 'True'
            deliveredDate = res["trackDetails"][0]['deliveredDate']

            if title == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            self.mysql_one(Primary_key,times, title, describes, Tracking_number, warehouse_sku, zhujians,deliveredDate, remark,
                           mysql_name='load_ups')
        print('*' * 30)



def times_(datas,datas_,datatime_time):#datas物流title，datas_物流平台，datatime_time节点时间

    if datas_=='jiufang':
        datatime_time = datetime.datetime.strptime(datatime_time, '%Y-%m-%d %H:%M:%S')
        if '已提取' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=2)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已到仓' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=4)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已清关' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=6)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已到港' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=7)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已离港' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=9)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已放行' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=10)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已出库' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=11)
            return 'jiufang计算后的时间{}'.format(datatime_)
        else:
            return None
    elif datas_=='dhl':
        dicts = {
            '十二月':'12',
            '十一月': '11',
            '十月': '10',
            '九月': '9',
            '八月': '8',
            '七月': '7',
            '六月': '6',
            '五月': '5',
            '四月': '4',
            '三月': '3',
            '二月': '2',
            '一月': '1'

        }
        datatime_time = datatime_time.split(', ')[2] + '/' + dicts[datatime_time.split(', ')[1].split(' ')[0]] + '/' + datatime_time.split(', ')[1].split(' ')[1]
        datatime_time = datetime.datetime.strptime(datatime_time, '%Y/%m/%d')
        if '已派送' in datas:
            return 'dhl计算后的时间1'
        elif '快件已完成清關手續並'in datas and '從海關放行' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=5)
            return 'dhl计算后的时间{}'.format(datatime_)
        elif '已抵達DHL中轉中心' in datas and 'HONG KONG' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=7)
            return 'dhl计算后的时间{}'.format(datatime_)
        else:
            return None

    elif datas_=='fedex':
        datatime_time = datetime.datetime.strptime(datatime_time, '%Y-%m-%d')
        if '已送达' in datas:
            return 'fedex计算后的时间1'
        elif '国际货物放行' in datas and '进口' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=5)
            return 'fedex计算后的时间{}'.format(datatime_)
        elif '已离开 FedEx' in datas and '始发地服务站' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=7)
            return 'fedex计算后的时间{}'.format(datatime_)
        else:
            return None
    elif datas_=='aaf':
        datatime_time = datetime.datetime.strptime(datatime_time, '%Y-%m-%d %H:%M:%S')
        if 'DELIVERED' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=2)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '货物已交付' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=4)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已清关放行' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=6)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '航班已抵达' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=7)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '航班已起飞' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=9)
            return 'jiufang计算后的时间{}'.format(datatime_)
        elif '已发出' in datas:
            datatime_ = datatime_time + datetime.timedelta(days=10)
            return 'jiufang计算后的时间{}'.format(datatime_)
        else:
            return None



if __name__ == '__main__':
    # screening_load是该文件的主函数
    run = Load()

    # run.return_mysql()
    run.screening_load()
